<?php
namespace app\center\controller;
use app\center\logic\IntegralLogic;

/**
 * 积分明细api控制器
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/11/27
 * Time: 17:09
 */
class Integral extends Base {

    public function __construct(){
        parent::__construct();
        $this->i_logic = new IntegralLogic();
    }

    /**
     * 获取积分明细
     * @return \think\response\Json
     */
    public function ajax_get_integral(){
        $params = input();
        $r = $this->check_user_token($params);
        if($r['code'] != 1){
            return json($r);
        }

        //检查用户规则
        $r = $this->i_logic->check_user_rule();
        if($r['code'] != 1){
            return json($r);
        }
        $u_detail = $r['data']['detail'];

        $maps = $this->i_logic->get_search_integral_maps($u_detail['openid']);
        $limit = ($params['page'] - 1) * $params['rows'];

        $list = model('integral_record')->get_list($maps,'id,integral,integral_desc,c_time','c_time desc','',$limit,$params['rows']);

        $data['list'] = $list;
        $data['page'] = $params['page'];
        return json($this->i_logic->get_response(1,'OK',$data));
    }
}
